package de.dopichaj.labrador.index.backend;

public final class Term {
    private final int id;
    private final String text;
    private int elementFrequency;
    private int documentFrequency;
    private int collectionFrequency;
    /**
     * The position in the index file.
     */
    private int indexPosition;
    
    public Term(final int id, final String text) {
        this(id, text, 1, 1, 1);
    }

    public Term(final int id, final String text, final int elementFrequency,
        final int documentFrequency, final int collectionFrequency) {

        this.id = id;
        this.text = text;
        this.elementFrequency = elementFrequency;
        this.documentFrequency = documentFrequency;
        this.collectionFrequency = collectionFrequency;
        this.indexPosition = Integer.MAX_VALUE;
    }
    
    public int getDocumentFrequency() {
        return documentFrequency;
    }
    public void increaseDocumentFrequency() {
        documentFrequency++;
    }
    public int getElementFrequency() {
        return elementFrequency;
    }
    public void increaseElementFrequency() {
        elementFrequency++;
    }
    public void increaseCollectionFrequency(final int delta) {
        this.collectionFrequency += delta;
    }
    public int getCollectionFrequency() {
        return collectionFrequency;
    }
    public int getID() {
        return id;
    }
    public String getText() {
        return text;
    }
    public void setIndexPosition(final int indexPosition) {
        this.indexPosition = indexPosition;
    }
    public int getIndexPosition() {
        return indexPosition;
    }
    public String toString() {
        return "Term " + getText() + " (" + getID() + "), " +
            "ef=" + getElementFrequency() + ", " +
            "df=" + getDocumentFrequency() + ", " +
            "cf=" + getCollectionFrequency() + ", " +
            "pos=" + getIndexPosition();
    }

    @Override
    public int hashCode() {
        return id;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final Term other = (Term)obj;
        if (id != other.id)
            return false;
        return true;
    }
}
/*
Copyright (c) 2007 Philipp Dopichaj

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/